package com.lianzheng.action;

import com.lianzheng.AppConst;
import com.lianzheng.UserVO;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.context.annotation.Scope;
import com.opensymphony.xwork2.ActionSupport;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-11-30
 * Time: 0:37:20
 */
@SuppressWarnings("serial")
@Scope("prototype")
@Controller
public class BaseAction extends ActionSupport {
    private static final Logger logger = Logger.getLogger(BaseAction.class);

    protected HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }

    protected String getContextPath() {
        return getRequest().getContextPath();
    }

    protected HttpServletResponse getResponse() {
        return ServletActionContext.getResponse();
    }

    protected HttpSession getSession() {
        return getRequest().getSession();
    }

    protected UserVO getUserPrincipal() {
        return (UserVO) getSession().getAttribute(AppConst.USER_KEY);
    }

    protected String getUserCode() {
        UserVO user = getUserPrincipal();
        return user.getUserId();
    }

}
